import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { EventName } from "../../../mvc/EventName";
import { ArenaGroupResult } from "./ArenaGroupResult";
import { ObjCreate } from "../../common/ObjCreate";
import { ArenaGroupDetail } from "./ArenaGroupDetail";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../../resource/ImagesConst";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { BaseItem } from "../../common/BaseItem";
import { GameMapUtil } from "../../../scene/map/GameMapUtil";
import { DataEvent } from "../../../events/DataEvent";
import { SArenaResult } from "../../../../../Message/Public/SArenaResult";
import { ItemData } from "../../../resource/info/ItemData";
import { SArenaPlayerResult } from "../../../../../Message/Public/SArenaPlayerResult";
import { Cache } from "../../../cache/Cache";
//class ArenaResultWindow
    
    export  class ArenaResultWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            setSize(377, 280);
            titleHeight = 26;
            title = Language.getString(42242);
            Dispatcher.addEventListener(EventName.ArenaShowArenaGroupDetails, this.showDetails);
            return;
        }

        protected /* override */ createChildren(): void
        {
            var loc2=NaN;
            var loc4=null;
            super.createChildren();
            this._arenaGroupResultOne = new ArenaGroupResult();
            ObjCreate.setObjAttri(this._arenaGroupResultOne, 17, 40, -1, -1, this);
            this._arenaGroupResultTwo = new ArenaGroupResult();
            ObjCreate.setObjAttri(this._arenaGroupResultTwo, 190, 40, -1, -1, this);
            this._arenaGroupDetail = new ArenaGroupDetail();
            ObjCreate.setObjAttri(this._arenaGroupDetail, 377, 0, -1, -1, this);
            var loc1=GlobalClass.getBitmap(ImagesConst.ArenaVS);
            ObjCreate.setObjAttri(loc1, 167, 98, -1, -1, this);
            loc2 = 210;
            var loc3=ObjCreate.createGButton(Language.getString(42243), 158, loc2 + 35, 55, 22, this);
            loc3.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnOKClick);
            loc4 = new GTextFormat(FontUtil.songtiName, 14, 15788607);
            this._tfExpReward = ObjCreate.createTextField(Language.getStringByParam(42244, "0"), 22, loc2, 150, 22, this, loc4);
            this._spItemReward = new Object /* flash.display.Sprite */();
            this._spItemReward.x = 188;
            this._spItemReward.y = loc2;
            this.addChild(this._spItemReward);
            this._tfItemReward = ObjCreate.createTextField(Language.getString(42245), 0, 0, 65, 22, this._spItemReward, loc4);
            this._tfItemReward.mouseEnabled = false;
            var loc5=GlobalClass.getBitmap(ImagesConst.PackItemBg);
            ObjCreate.setObjAttri(loc5, 65, 0, -1, -1, this._spItemReward);
            this._baseItem = new BaseItem();
            ObjCreate.setObjAttri(this._baseItem, 68, 3, -1, -1, this._spItemReward);
            var loc6=new GTextFormat(FontUtil.songtiName, 14, 15788607);
            this._tfMoneyReward = ObjCreate.createTextField(Language.getStringByParam(42246, "0"), 22, loc2 + 20, 150, 22, this, loc6);
            return;
        }

        /* internal  */onBtnOKClick(arg1: Object /* flash.events.MouseEvent */): void
        {
            this.hide();
            if (GameMapUtil.isArena()) 
            {
                Dispatcher.dispatchEvent(new DataEvent(EventName.ArenaExitNow));
            }
            return;
        }

        /* internal  */showDetails(arg1: DataEvent): void
        {
            this._arenaGroupDetail.visible = true;
            return;
        }

        public updateResult(arg1: SArenaResult): void
        {
            this._arenaGroupDetail.visible = false;
            if (arg1.groupOne.length > 1) 
            {
                this._arenaGroupDetail.updateData(arg1.groupOne);
            }
            if (arg1.groupTwo.length > 1) 
            {
                this._arenaGroupDetail.updateData(arg1.groupTwo);
            }
            this._arenaGroupResultOne.updateResult(arg1.groupOne, arg1.groupOneResult, false, arg1.leftNumOne);
            this._arenaGroupResultTwo.updateResult(arg1.groupTwo, arg1.groupTwoResult, false, arg1.leftNumTwo);
            this._tfExpReward.text = Language.getStringByParam(42244, arg1.expReward.toString());
            this._tfMoneyReward.text = Language.getStringByParam(42246, arg1.moneyReward.toString());
            if (arg1.itemReward != 0) 
            {
                this._spItemReward.visible = true;
                this._baseItem.itemData = new ItemData(arg1.itemReward);
                this._baseItem.width = 32;
                this._baseItem.height = 32;
                this._baseItem.drawNow();
            }
            else 
            {
                this._spItemReward.visible = false;
            }
            if (arg1.isBattler) 
            {
                this._tfExpReward.visible = true;
                this._tfMoneyReward.visible = true;
            }
            else 
            {
                this._tfExpReward.visible = false;
                this._tfMoneyReward.visible = false;
            }
            return;
        }

        /* internal  */getPlayerResult(arg1: SArenaResult): SArenaPlayerResult
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < arg1.groupOne.length) 
            {
                loc1 = arg1.groupOne[loc2] as SArenaPlayerResult;
                if (loc1.miniPlayer.entityId.id == Cache.instance.role.entityInfo.entityId.id) 
                {
                    return loc1;
                }
                ++loc2;
            }
            return null;
        }

        /* internal  */layOut(): void
        {
            return;
        }

        public clean(): void
        {
            this.hide();
            Dispatcher.removeEventListener(EventName.ArenaShowArenaGroupDetails, this.showDetails);
            return;
        }

        /* internal */ /* var */_arenaGroupResultOne: ArenaGroupResult;

        /* internal */ /* var */_arenaGroupResultTwo: ArenaGroupResult;

        /* internal */ /* var */_arenaGroupDetail: ArenaGroupDetail;

        /* internal */ /* var */_tfExpReward: Object /* flash.text.TextField */;

        /* internal */ /* var */_spItemReward: Object /* flash.display.Sprite */;

        /* internal */ /* var */_tfItemReward: Object /* flash.text.TextField */;

        /* internal */ /* var */_baseItem: BaseItem;

        /* internal */ /* var */_tfMoneyReward: Object /* flash.text.TextField */;
    }
